package panels;

import javax.swing.table.*;
import java.util.*;

public class DataBrowserModel extends AbstractTableModel {
	public ArrayList contents = null;
	public ArrayList fieldNames = null;

	public DataBrowserModel() {
		super();
		contents = new ArrayList(32);
		fieldNames = new ArrayList();
	}

	public String getColumnName(int column) {
		if (column >= this.fieldNames.size())
			return "";
		return (String) fieldNames.get(column);
	}

	public int getRowCount() {
		return contents.size();
	}

	public int getColumnCount() {
		return this.fieldNames.size();
	}

	public Object getValueAt(int row, int column) {
		if (false == this.isCellIndexValid(row, column))
			return "";
		return ((ArrayList) (contents.get(row))).get(column);
	}

	public void setValueAt(Object value, int row, int column) {
		if (false == this.isCellIndexValid(row, column))
			return;
		((ArrayList) contents.get(row)).set(column, value);
	}

	public void clear() {
		this.contents.clear();
		this.fieldNames.clear();
		this.fireTableStructureChanged();
	}

	private boolean isCellIndexValid(int row, int column) {
		return ((row < this.contents.size()) && (column < ((ArrayList) (contents.get(row))).size()));
	}
}
